package com.game.fighting.socket;

import com.game.fighting.message.MsgHandler;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;

/**
 * Copyright (C), 2021-2041, chenc 豫R7HQ53
 *
 * @author: chenc
 * Date:     2023/12/5 19:13
 * Description:
 */
@Slf4j
public class SocketClient extends WebSocketClient {

    public SocketClient(URI serverUri) {
        super(serverUri);
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        log.info("连接到游戏服务器。。。");
    }

    @Override
    public void onMessage(String s) {
        MsgHandler.handlerMsg(s);
    }

    @Override
    public void onClose(int i, String s, boolean b) {
        log.info("关闭到游戏服务器的连接。。。");
    }

    @Override
    public void onError(Exception e) {
        log.info("收发消息出错。。。", e);
    }
}
